// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.worldMap.styles;

import java.util.ArrayList;
import java.util.Objects;
import zombie.Lua.LuaManager;
import zombie.core.math.PZMath;
import zombie.core.textures.Texture;
import zombie.worldMap.UIWorldMap;
import zombie.worldMap.UIWorldMapV1;

public class WorldMapStyleV1 {
    public UIWorldMap m_ui;
    public UIWorldMapV1 m_api;
    public WorldMapStyle m_style;
    public final ArrayList<WorldMapStyleV1.WorldMapStyleLayerV1> m_layers = new ArrayList();

    public WorldMapStyleV1(UIWorldMap ui) {
        Objects.requireNonNull(ui);
        this.m_ui = ui;
        this.m_api = ui.getAPIv1();
        this.m_style = this.m_api.getStyle();
    }

    public WorldMapStyleV1.WorldMapStyleLayerV1 newLineLayer(String id) throws IllegalArgumentException {
        WorldMapStyleV1.WorldMapLineStyleLayerV1 worldMapLineStyleLayerV1 = new WorldMapStyleV1.WorldMapLineStyleLayerV1(this, id);
        this.m_layers.add(worldMapLineStyleLayerV1);
        return worldMapLineStyleLayerV1;
    }

    public WorldMapStyleV1.WorldMapStyleLayerV1 newPolygonLayer(String id) throws IllegalArgumentException {
        WorldMapStyleV1.WorldMapPolygonStyleLayerV1 worldMapPolygonStyleLayerV1 = new WorldMapStyleV1.WorldMapPolygonStyleLayerV1(this, id);
        this.m_layers.add(worldMapPolygonStyleLayerV1);
        return worldMapPolygonStyleLayerV1;
    }

    public WorldMapStyleV1.WorldMapStyleLayerV1 newTextureLayer(String id) throws IllegalArgumentException {
        WorldMapStyleV1.WorldMapTextureStyleLayerV1 worldMapTextureStyleLayerV1 = new WorldMapStyleV1.WorldMapTextureStyleLayerV1(this, id);
        this.m_layers.add(worldMapTextureStyleLayerV1);
        return worldMapTextureStyleLayerV1;
    }

    public int getLayerCount() {
        return this.m_layers.size();
    }

    public WorldMapStyleV1.WorldMapStyleLayerV1 getLayerByIndex(int index) {
        return (WorldMapStyleV1.WorldMapStyleLayerV1)this.m_layers.get(index);
    }

    public WorldMapStyleV1.WorldMapStyleLayerV1 getLayerByName(String id) {
        int _int = this.indexOfLayer(id);
        return _int == -1 ? null : (WorldMapStyleV1.WorldMapStyleLayerV1)this.m_layers.get(_int);
    }

    public int indexOfLayer(String id) {
        for (int _int = 0; _int < this.m_layers.size(); _int++) {
            WorldMapStyleV1.WorldMapStyleLayerV1 worldMapStyleLayerV1 = (WorldMapStyleV1.WorldMapStyleLayerV1)this.m_layers.get(_int);
            if (worldMapStyleLayerV1.m_layer.m_id.equals(id)) {
                return _int;
            }
        }

        return -1;
    }

    public void moveLayer(int indexFrom, int indexTo) {
        WorldMapStyleLayer worldMapStyleLayer = (WorldMapStyleLayer)this.m_style.m_layers.remove(indexFrom);
        this.m_style.m_layers.add(indexTo, worldMapStyleLayer);
        WorldMapStyleV1.WorldMapStyleLayerV1 worldMapStyleLayerV1 = (WorldMapStyleV1.WorldMapStyleLayerV1)this.m_layers.remove(indexFrom);
        this.m_layers.add(indexTo, worldMapStyleLayerV1);
    }

    public void removeLayerById(String id) {
        int _int = this.indexOfLayer(id);
        if (_int != -1) {
            this.removeLayerByIndex(_int);
        }
    }

    public void removeLayerByIndex(int index) {
        this.m_style.m_layers.remove(index);
        this.m_layers.remove(index);
    }

    public void clear() {
        this.m_style.m_layers.clear();
        this.m_layers.clear();
    }

    public static void setExposed(LuaManager.Exposer exposer) {
        exposer.setExposed(WorldMapStyleV1.class);
        exposer.setExposed(WorldMapStyleV1.WorldMapStyleLayerV1.class);
        exposer.setExposed(WorldMapStyleV1.WorldMapLineStyleLayerV1.class);
        exposer.setExposed(WorldMapStyleV1.WorldMapPolygonStyleLayerV1.class);
        exposer.setExposed(WorldMapStyleV1.WorldMapTextureStyleLayerV1.class);
    }

    public static class WorldMapLineStyleLayerV1 extends WorldMapStyleV1.WorldMapStyleLayerV1 {
        WorldMapLineStyleLayer m_lineStyle = (WorldMapLineStyleLayer)this.m_layer;

        WorldMapLineStyleLayerV1(WorldMapStyleV1 worldMapStyleV1, String string) {
            super(worldMapStyleV1, new WorldMapLineStyleLayer(string));
        }

        public void setFilter(String key, String value) {
            this.m_lineStyle.m_filterKey = key;
            this.m_lineStyle.m_filterValue = value;
            this.m_lineStyle.m_filter = (worldMapFeature, var3) -> worldMapFeature.hasLineString() && value.equals(worldMapFeature.m_properties.get(key));
        }

        public void addFill(float zoom, int r, int g, int b, int a) {
            this.m_lineStyle.m_fill.add(new WorldMapStyleLayer.ColorStop(zoom, r, g, b, a));
        }

        public void addLineWidth(float zoom, float width) {
            this.m_lineStyle.m_lineWidth.add(new WorldMapStyleLayer.FloatStop(zoom, width));
        }
    }

    public static class WorldMapPolygonStyleLayerV1 extends WorldMapStyleV1.WorldMapStyleLayerV1 {
        WorldMapPolygonStyleLayer m_polygonStyle = (WorldMapPolygonStyleLayer)this.m_layer;

        WorldMapPolygonStyleLayerV1(WorldMapStyleV1 worldMapStyleV1, String string) {
            super(worldMapStyleV1, new WorldMapPolygonStyleLayer(string));
        }

        public void setFilter(String key, String value) {
            this.m_polygonStyle.m_filterKey = key;
            this.m_polygonStyle.m_filterValue = value;
            this.m_polygonStyle.m_filter = (worldMapFeature, var3) -> worldMapFeature.hasPolygon() && value.equals(worldMapFeature.m_properties.get(key));
        }

        public String getFilterKey() {
            return this.m_polygonStyle.m_filterKey;
        }

        public String getFilterValue() {
            return this.m_polygonStyle.m_filterValue;
        }

        public void addFill(float zoom, int r, int g, int b, int a) {
            this.m_polygonStyle.m_fill.add(new WorldMapStyleLayer.ColorStop(zoom, r, g, b, a));
        }

        public void addScale(float zoom, float scale) {
            this.m_polygonStyle.m_scale.add(new WorldMapStyleLayer.FloatStop(zoom, scale));
        }

        public void addTexture(float zoom, String texturePath) {
            this.m_polygonStyle.m_texture.add(new WorldMapStyleLayer.TextureStop(zoom, texturePath));
        }

        public void removeFill(int index) {
            this.m_polygonStyle.m_fill.remove(index);
        }

        public void removeTexture(int index) {
            this.m_polygonStyle.m_texture.remove(index);
        }

        public void moveFill(int indexFrom, int indexTo) {
            WorldMapStyleLayer.ColorStop colorStop = (WorldMapStyleLayer.ColorStop)this.m_polygonStyle.m_fill.remove(indexFrom);
            this.m_polygonStyle.m_fill.add(indexTo, colorStop);
        }

        public void moveTexture(int indexFrom, int indexTo) {
            WorldMapStyleLayer.TextureStop textureStop = (WorldMapStyleLayer.TextureStop)this.m_polygonStyle.m_texture.remove(indexFrom);
            this.m_polygonStyle.m_texture.add(indexTo, textureStop);
        }

        public int getFillStops() {
            return this.m_polygonStyle.m_fill.size();
        }

        public void setFillRGBA(int index, int r, int g, int b, int a) {
            ((WorldMapStyleLayer.ColorStop)this.m_polygonStyle.m_fill.get(index)).r = r;
            ((WorldMapStyleLayer.ColorStop)this.m_polygonStyle.m_fill.get(index)).g = g;
            ((WorldMapStyleLayer.ColorStop)this.m_polygonStyle.m_fill.get(index)).b = b;
            ((WorldMapStyleLayer.ColorStop)this.m_polygonStyle.m_fill.get(index)).a = a;
        }

        public void setFillZoom(int index, float zoom) {
            ((WorldMapStyleLayer.ColorStop)this.m_polygonStyle.m_fill.get(index)).m_zoom = PZMath.clamp(zoom, 0.0F, 24.0F);
        }

        public float getFillZoom(int index) {
            return ((WorldMapStyleLayer.ColorStop)this.m_polygonStyle.m_fill.get(index)).m_zoom;
        }

        public int getFillRed(int index) {
            return ((WorldMapStyleLayer.ColorStop)this.m_polygonStyle.m_fill.get(index)).r;
        }

        public int getFillGreen(int index) {
            return ((WorldMapStyleLayer.ColorStop)this.m_polygonStyle.m_fill.get(index)).g;
        }

        public int getFillBlue(int index) {
            return ((WorldMapStyleLayer.ColorStop)this.m_polygonStyle.m_fill.get(index)).b;
        }

        public int getFillAlpha(int index) {
            return ((WorldMapStyleLayer.ColorStop)this.m_polygonStyle.m_fill.get(index)).a;
        }

        public int getTextureStops() {
            return this.m_polygonStyle.m_texture.size();
        }

        public void setTextureZoom(int index, float zoom) {
            ((WorldMapStyleLayer.TextureStop)this.m_polygonStyle.m_texture.get(index)).m_zoom = PZMath.clamp(zoom, 0.0F, 24.0F);
        }

        public float getTextureZoom(int index) {
            return ((WorldMapStyleLayer.TextureStop)this.m_polygonStyle.m_texture.get(index)).m_zoom;
        }

        public void setTexturePath(int index, String texturePath) {
            ((WorldMapStyleLayer.TextureStop)this.m_polygonStyle.m_texture.get(index)).texturePath = texturePath;
            ((WorldMapStyleLayer.TextureStop)this.m_polygonStyle.m_texture.get(index)).texture = Texture.getTexture(texturePath);
        }

        public String getTexturePath(int index) {
            return ((WorldMapStyleLayer.TextureStop)this.m_polygonStyle.m_texture.get(index)).texturePath;
        }

        public Texture getTexture(int index) {
            return ((WorldMapStyleLayer.TextureStop)this.m_polygonStyle.m_texture.get(index)).texture;
        }
    }

    public static class WorldMapStyleLayerV1 {
        WorldMapStyleV1 m_owner;
        WorldMapStyleLayer m_layer;

        WorldMapStyleLayerV1(WorldMapStyleV1 worldMapStyleV1, WorldMapStyleLayer worldMapStyleLayer) {
            this.m_owner = worldMapStyleV1;
            this.m_layer = worldMapStyleLayer;
            worldMapStyleV1.m_style.m_layers.add(this.m_layer);
        }

        public String getTypeString() {
            return this.m_layer.getTypeString();
        }

        public void setId(String id) {
            this.m_layer.m_id = id;
        }

        public String getId() {
            return this.m_layer.m_id;
        }

        public void setMinZoom(float minZoom) {
            this.m_layer.m_minZoom = minZoom;
        }

        public float getMinZoom() {
            return this.m_layer.m_minZoom;
        }
    }

    public static class WorldMapTextureStyleLayerV1 extends WorldMapStyleV1.WorldMapStyleLayerV1 {
        WorldMapTextureStyleLayer m_textureStyle = (WorldMapTextureStyleLayer)this.m_layer;

        WorldMapTextureStyleLayerV1(WorldMapStyleV1 worldMapStyleV1, String string) {
            super(worldMapStyleV1, new WorldMapTextureStyleLayer(string));
        }

        public void addFill(float zoom, int r, int g, int b, int a) {
            this.m_textureStyle.m_fill.add(new WorldMapStyleLayer.ColorStop(zoom, r, g, b, a));
        }

        public void addTexture(float zoom, String texturePath) {
            this.m_textureStyle.m_texture.add(new WorldMapStyleLayer.TextureStop(zoom, texturePath));
        }

        public void removeFill(int index) {
            this.m_textureStyle.m_fill.remove(index);
        }

        public void removeAllFill() {
            this.m_textureStyle.m_fill.clear();
        }

        public void removeTexture(int index) {
            this.m_textureStyle.m_texture.remove(index);
        }

        public void removeAllTexture() {
            this.m_textureStyle.m_texture.clear();
        }

        public void moveFill(int indexFrom, int indexTo) {
            WorldMapStyleLayer.ColorStop colorStop = (WorldMapStyleLayer.ColorStop)this.m_textureStyle.m_fill.remove(indexFrom);
            this.m_textureStyle.m_fill.add(indexTo, colorStop);
        }

        public void moveTexture(int indexFrom, int indexTo) {
            WorldMapStyleLayer.TextureStop textureStop = (WorldMapStyleLayer.TextureStop)this.m_textureStyle.m_texture.remove(indexFrom);
            this.m_textureStyle.m_texture.add(indexTo, textureStop);
        }

        public void setBoundsInSquares(int minX, int minY, int maxX, int maxY) {
            this.m_textureStyle.m_worldX1 = minX;
            this.m_textureStyle.m_worldY1 = minY;
            this.m_textureStyle.m_worldX2 = maxX;
            this.m_textureStyle.m_worldY2 = maxY;
        }

        public int getMinXInSquares() {
            return this.m_textureStyle.m_worldX1;
        }

        public int getMinYInSquares() {
            return this.m_textureStyle.m_worldY1;
        }

        public int getMaxXInSquares() {
            return this.m_textureStyle.m_worldX2;
        }

        public int getMaxYInSquares() {
            return this.m_textureStyle.m_worldY2;
        }

        public int getWidthInSquares() {
            return this.m_textureStyle.m_worldX2 - this.m_textureStyle.m_worldX1;
        }

        public int getHeightInSquares() {
            return this.m_textureStyle.m_worldY2 - this.m_textureStyle.m_worldY1;
        }

        public void setTile(boolean tile) {
            this.m_textureStyle.m_tile = tile;
        }

        public boolean isTile() {
            return this.m_textureStyle.m_tile;
        }

        public void setUseWorldBounds(boolean useWorldBounds) {
            this.m_textureStyle.m_useWorldBounds = useWorldBounds;
        }

        public boolean isUseWorldBounds() {
            return this.m_textureStyle.m_useWorldBounds;
        }

        public int getFillStops() {
            return this.m_textureStyle.m_fill.size();
        }

        public void setFillRGBA(int index, int r, int g, int b, int a) {
            ((WorldMapStyleLayer.ColorStop)this.m_textureStyle.m_fill.get(index)).r = r;
            ((WorldMapStyleLayer.ColorStop)this.m_textureStyle.m_fill.get(index)).g = g;
            ((WorldMapStyleLayer.ColorStop)this.m_textureStyle.m_fill.get(index)).b = b;
            ((WorldMapStyleLayer.ColorStop)this.m_textureStyle.m_fill.get(index)).a = a;
        }

        public void setFillZoom(int index, float zoom) {
            ((WorldMapStyleLayer.ColorStop)this.m_textureStyle.m_fill.get(index)).m_zoom = PZMath.clamp(zoom, 0.0F, 24.0F);
        }

        public float getFillZoom(int index) {
            return ((WorldMapStyleLayer.ColorStop)this.m_textureStyle.m_fill.get(index)).m_zoom;
        }

        public int getFillRed(int index) {
            return ((WorldMapStyleLayer.ColorStop)this.m_textureStyle.m_fill.get(index)).r;
        }

        public int getFillGreen(int index) {
            return ((WorldMapStyleLayer.ColorStop)this.m_textureStyle.m_fill.get(index)).g;
        }

        public int getFillBlue(int index) {
            return ((WorldMapStyleLayer.ColorStop)this.m_textureStyle.m_fill.get(index)).b;
        }

        public int getFillAlpha(int index) {
            return ((WorldMapStyleLayer.ColorStop)this.m_textureStyle.m_fill.get(index)).a;
        }

        public int getTextureStops() {
            return this.m_textureStyle.m_texture.size();
        }

        public void setTextureZoom(int index, float zoom) {
            ((WorldMapStyleLayer.TextureStop)this.m_textureStyle.m_texture.get(index)).m_zoom = PZMath.clamp(zoom, 0.0F, 24.0F);
        }

        public float getTextureZoom(int index) {
            return ((WorldMapStyleLayer.TextureStop)this.m_textureStyle.m_texture.get(index)).m_zoom;
        }

        public void setTexturePath(int index, String texturePath) {
            ((WorldMapStyleLayer.TextureStop)this.m_textureStyle.m_texture.get(index)).texturePath = texturePath;
            ((WorldMapStyleLayer.TextureStop)this.m_textureStyle.m_texture.get(index)).texture = Texture.getTexture(texturePath);
        }

        public String getTexturePath(int index) {
            return ((WorldMapStyleLayer.TextureStop)this.m_textureStyle.m_texture.get(index)).texturePath;
        }

        public Texture getTexture(int index) {
            return ((WorldMapStyleLayer.TextureStop)this.m_textureStyle.m_texture.get(index)).texture;
        }
    }
}
